﻿Imports Microsoft.International.Converters.PinYinConverter

Public Module modGlobal
    '定义全局常量
    '全局的字符串连接模板
    Public sysConnectionTemplate As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};Persist Security Info=True"
    '全局的程序信息类对象
    Public sysClsApp As ClsApp
    '全局的当前账套操作的信息对象
    Public sysCurrentClsLedger As ClsLedger
    '全局的当前登录的用户对象
    Public sysCurrentClsUser As ClsUser
    '全局主窗体对象
    Public sysFrmMdiMain As New frmMdiMain
    '定义一个dictionary,用来存放每个标题按钮对应的flowlayoutpanel
    Public sysBtnTitleDic As Dictionary(Of String, Object)
    '定义一个dictionary，用来存放每个具体工具对应的窗体类的类型 - 
    Public sysBtnItemDic As Dictionary(Of String, Type)
    '当前mdi窗体打开的子窗体列表

    '当前程序运行路径
    Public sysAppCurrentPath As String
    '数据目录
    Public Const APP_DATA_PATH = "data"

    '模板数据库文件连接 - example.mdb
    Public sysDataTemplateConnectionString As String
    '账套模板所在数据库文件名称
    Public Const APP_DATA_NAME_TEMPLATE = "sample.mdb"

    '数据库文件连接 - sys.mdb
    Public sysAppInfoConnectionString As String
    '系统表所在库名称
    Public Const APP_DATA_NAME_SYS = "sys.mdb"
    '系统库sys.mdb中各表名称
    Public Const TABLE_NAME_USERLEDGER = "S_UserLedger"
    Public Const TABLE_NAME_USER = "S_User"
    Public Const TABLE_NAME_LEDGER = "S_Ledger"
    Public Const TABLE_NAME_APP = "S_App"
    Public Const TABLE_NAME_INDUSTRY_ACCOUNT = "S_IndustryAccount"
    Public Const TABLE_NAME_INDUSTRY_ACCOUNT_TYPE = "S_IndustryAccountType"
    Public Const TABLE_NAME_INDUSTRY_ACCOUNT_GROUP = "S_IndustryAcctGroup"


    '用户数据库文件连接 - 当前打开账套
    Public sysUserDataConnectionString As String
    '当前打开账套的参数对象变量(ClsTLedgerSetting)
    Public sysCurrentLedgerSetting As ClsTLedgerSetting
    '当前打开的用户账套数据库文件名称
    'Public currentUserDataName As String
    '用户账套数据文件中表名称
    Public Const TABLE_NAME_T_LEDGER_SETTING = "T_LedgerSetting"
    Public Const TABLE_NAME_T_VOUCHER_GROUP = "T_VoucherGroup" '凭证类别表
    Public Const TABLE_NAME_T_VOUCHER_NUMBER = "T_VoucherNumber" '凭证类别编号表
    Public Const TABLE_NAME_T_VOUCHER_MAXNUMBER = "T_MaxNumberOfVoucher" '凭证最大编号表

    Public Const TABLE_NAME_T_ACCOUNT = "T_Account" '科目表
    Public Const TABLE_NAME_T_VOUCHER = "T_Voucher" '凭证表
    Public Const TABLE_NAME_T_VOUCHER_DETAIL = "T_VoucherDetail" '凭证明细表
    Public Const TABLE_NAME_T_EMPLOYEE = "T_Employee" '个人表
    Public Const TABLE_NAME_T_DEPARTMENT = "T_Department" '部门表
    Public Const TABLE_NAME_T_CUSTOMER = "T_Customer" '往来单位表
    Public Const TABLE_NAME_T_BOOK_INIT = "T_BookInit" '年初平衡表

    Public Const TABLE_NAME_T_QUANTITY_SUM = "T_QuantitySum" '科目汇总表（数量）
    Public Const TABLE_NAME_T_CURRENCY_SUM = "T_CurrencySum" '科目汇总表（外币）
    Public Const TABLE_NAME_T_ACCOUNT_SUM = "T_AccountSum" '科目汇总表（金额）
    Public Const TABLE_NAME_T_DETAIL_REPORT = "T_DetailReport" '科目明细账表

    Public Const TABLE_NAME_T_BALANCE_MONEY = "T_BalanceMoney" '科目余额表-金额
    Public Const TABLE_NAME_T_BALANCE_QUANTITY = "T_BalanceQuantity" '科目余额表-数量

    Public Const TABLE_NAME_T_GENERAL_MONEY_LEDGER = "T_GeneralMoneyLedger" '总账数据表-金额
    Public Const TABLE_NAME_T_GENERAL_QUANTITY_LEDGER = "T_GeneralQuantityLedger" '总账数据表-数量
    Public Const TABLE_NAME_T_GENERAL_CURRENCY_LEDGER = "T_GeneralCurrencyLedger" '总账数据表-外币
    Public Const TABLE_NAME_T_WORK_PERIOD = "T_WorkPeriod" '会计期间表


    '锐剑财务系统数据表变量
    Public Const TABLE_NAME_RJ_SYS_SOFTINFO = "sysSoftInfo" '程序信息表，用业判断mde文件是否为锐剑系统文件
    Public Const TABLE_NAME_RJ_MY_YEAR = "myyear" '账套信息表，用来判断 mdb文件是否为锐剑系统文件的备份文件
    Public Const TABLE_NAME_RJ_ACCT_SETUP = "科目配置表"
    Public Const TABLE_NAME_RJ_VOUCHER = "记账凭证库"
    Public Const TABLE_NAME_RJ_WORKPERIOD = "会计期间表"
    Public Const TABLE_NAME_RJ_ACCT = "会计科目表2"
    Public Const TABLE_NAME_RJ_VOUCHER_TYPE = "凭证类别库"

    '程序运行错误代码
    Public Const ERROR_NUMBER_CONTROL = 10010 '控件操作错误

    '导航窗格窗体对象全局变量
    Public sysAppFrmNavigateForm As frmNavigate

    '全局的AB账设置数组
    Public sysAbState() As String = {"不分AB账", "当前账套是A账", "当前账套是B账"}

    '导航窗体的常量
    Public Const FORM_NAVAGATE_BUTTON_WIDTH = 160 '导航窗口中控件宽度
    Public Const FORM_NAVAGATE_BUTTON_HEIGHT = 40
    Public Const FORM_NAVAGATE_ITEM_HEIGHT = 30
    '导航窗体左侧按钮组名称
    Public Const NAV_GROUP_VOUCHER_ITEM_NUMBER = 11
    Public Const NAV_TITLE_VOUCHER_TAG = "TitleVoucher"
    Public Const NAV_TITLE_VOUCHER_TEXT = "凭证处理"
    Public Const NAV_ITEM_INPUT_VOUCHER_TEXT = "录入本月凭证"
    Public Const NAV_ITEM_INPUT_VOUCHER_TAG = "ItemInputVoucher"
    Public Const NAV_ITEM_EDIT_VOUCHER_TEXT = "修改凭证"
    Public Const NAV_ITEM_EDIT_VOUCHER_TAG = "ItemEditVoucher"
    Public Const NAV_ITEM_CHECKUP_VOUCHER_TEXT = "审核凭证"
    Public Const NAV_ITEM_CHECKUP_VOUCHER_TAG = "ItemCheckupVoucher"
    Public Const NAV_ITEM_DELETE_VOUCHER_TEXT = "删除凭证"
    Public Const NAV_ITEM_DELETE_VOUCHER_TAG = "ItemDeleteVoucher"
    Public Const NAV_ITEM_BROWSE_VOUCHER_TEXT = "浏览打印凭证"
    Public Const NAV_ITEM_LOOKUP_VOUCHER_TAG = "ItemLookupVoucher"
    Public Const NAV_ITEM_LOOKUP_VOUCHER_TEXT = "查找凭证"
    Public Const NAV_ITEM_REPAIR_VOUCHER_TAG = "ItemRepairVoucher"
    Public Const NAV_ITEM_REPAIR_VOUCHER_TEXT = "修复凭证"
    Public Const NAV_ITEM_BROWSE_VOUCHER_TAG = "ItemBrowseVoucher"
    Public Const NAV_ITEM_INPUTFROMRJCW_VOUCHER_TEXT = "从锐剑财务系统导入凭证"
    Public Const NAV_ITEM_INPUTFROMRJCW_VOUCHER_TAG = "ItemInputFromRjcwVoucher"
    Public Const NAV_ITEM_INPUTFROMEXCEL_VOUCHER_TEXT = "从Excel文件导入凭证"
    Public Const NAV_ITEM_INPUTFROMEXCEL_VOUCHER_TAG = "ItemInputFromExcelVoucher"
    Public Const NAV_ITEM_INPUTGENEXCEL_VOUCHER_TEXT = "从Excel文件生成凭证"
    Public Const NAV_ITEM_INPUTGENEXCEL_VOUCHER_TAG = "ItemInputGenExcelVoucher"
    Public Const NAV_ITEM_OUTPUTTOEXCEL_VOUCHER_TEXT = "导出凭证"
    Public Const NAV_ITEM_OUTPUTTOEXCEL_VOUCHER_TAG = "ItemOutputToExcelVoucher"

    Public Const NAV_GROUP_LEDGER_ITEM_NUMBER = 8 '组内栏目条数
    Public Const NAV_TITLE_LEDGER_TAG = "TitleLedger"
    Public Const NAV_TITLE_LEDGER_TEXT = "账薄处理"
    Public Const NAV_ITEM_POST_VOUCHER_TAG = "ItemPostVoucher"
    Public Const NAV_ITEM_POST_VOUCHER_TEXT = "凭证过账"
    Public Const NAV_ITEM_SETTLEMONTH_LEDGER_TAG = "ItemSettleMonthLedger"
    Public Const NAV_ITEM_SETTLEMONTH_LEDGER_TEXT = "本月结账"
    Public Const NAV_ITEM_UNPOST_LEDGER_TAG = "ItemUnPostLedger"
    Public Const NAV_ITEM_UNPOST_LEDGER_TEXT = "本月反过账/反结账"
    Public Const NAV_ITEM_SUMACCOUNT_LEDGER_TAG = "ItemSumAccountLedger"
    Public Const NAV_ITEM_SUMACCOUNT_LEDGER_TEXT = "科目汇总表"
    Public Const NAV_ITEM_ACCOUNTBALANCE_LEDGER_TAG = "ItemAccountBalanceLedger"
    Public Const NAV_ITEM_ACCOUNTBALANCE_LEDGER_TEXT = "科目金额余额表"
    Public Const NAV_ITEM_QUANTITYBALANCE_LEDGER_TAG = "ItemQuantityBalanceLedger"
    Public Const NAV_ITEM_QUANTITYBALANCE_LEDGER_TEXT = "科目数量余额表"
    Public Const NAV_ITEM_FAKEPOST_LEDGER_TAG = "ItemFakePostLedger"
    Public Const NAV_ITEM_FAKEPOST_LEDGER_TEXT = "模拟过账"
    Public Const NAV_ITEM_INCANDDEC_LEDGER_TAG = "ItemIncAndDecLedger"
    Public Const NAV_ITEM_INCANDDEC_LEDGER_TEXT = "本月自动损益结转"

    Public Const NAV_GROUP_REPORT_ITEM_NUMBER = 6 '组内栏目条数
    Public Const NAV_TITLE_REPORT_TEXT = "报表处理"
    Public Const NAV_TITLE_REPORT_TAG = "TitleReport"
    Public Const NAV_ITEM_ACCTDETAIL_REPORT_TAG = "ItemAcctDetailReport"
    Public Const NAV_ITEM_ACCTDETAIL_REPORT_TEXT = "科目明细账报表"
    Public Const NAV_ITEM_GENERALLEDGER_REPORT_TAG = "ItemGeneralLedgerReport"
    Public Const NAV_ITEM_GENERALLEDGER_REPORT_TEXT = "科目总账报表"
    Public Const NAV_ITEM_FINANCIALSTATEMENT_REPORT_TAG = "ItemFinancialStatementReport"
    Public Const NAV_ITEM_FINANCIALSTATEMENT_REPORT_TEXT = "标准财务报表"
    Public Const NAV_ITEM_DEFINEMULTICOLUMN_REPORT_TAG = "ItemDefineMultiColumnReport"
    Public Const NAV_ITEM_DEFINEMULTICOLUMN_REPORT_TEXT = "定义多栏账报表"
    Public Const NAV_ITEM_MULTICOLUMN_REPORT_TAG = "ItemMultiColumnReport"
    Public Const NAV_ITEM_MULTICOLUMN_REPORT_TEXT = "科目多栏账报表"
    Public Const NAV_ITEM_COMBOCOLUMN_REPORT_TAG = "ItemComboColumnReport"
    Public Const NAV_ITEM_COMBOCOLUMN_REPORT_TEXT = "组合明细账报表"

    Public Const NAV_GROUP_FINANCIAL_SETUP_ITEM_NUMBER = 6 '财务设置组内栏目条数
    Public Const NAV_TITLE_FINANCIAL_SETUP_TEXT = "财务设置"
    Public Const NAV_TITLE_FINANCIAL_SETUP_TAG = "TitleFinancialSetup"
    Public Const NAV_ITEM_ACCT_FINANCIALSETUP_TAG = "ItemAcctFinancialSetup"
    Public Const NAV_ITEM_ACCT_FINANCIALSETUP_TEXT = "科目设置"
    Public Const NAV_ITEM_INPUT_ACCT_FINANCIALSETUP_TAG = "ItemInputAcctFinancialSetup"
    Public Const NAV_ITEM_INPUT_ACCT_FINANCIALSETUP_TEXT = "导入科目"
    Public Const NAV_ITEM_REPAIR_ACCT_FINANCIALSETUP_TAG = "ItemRepairAcctFinancialSetup"
    Public Const NAV_ITEM_REPAIR_ACCT_FINANCIALSETUP_TEXT = "科目修复"
    Public Const NAV_ITEM_SPECIAL_PROJECT_FINANCIALSETUP_TAG = "ItemSpecialProjectFinancialSetup"
    Public Const NAV_ITEM_SPECIAL_PROJECT_FINANCIALSETUP_TEXT = "专项设置"
    Public Const NAV_ITEM_VOUCHER_TYPE_FINANCIALSETUP_TAG = "ItemVoucherTypeFinancialSetup"
    Public Const NAV_ITEM_VOUCHER_TYPE_FINANCIALSETUP_TEXT = "凭证类别"
    Public Const NAV_ITEM_GLOBAL_PRINT_FINANCIALSETUP_TAG = "ItemGlobalPrintFinancialSetup"
    Public Const NAV_ITEM_GLOBAL_PRINT_FINANCIALSETUP_TEXT = "全局打印设置"

    Public Const NAV_GROUP_SYS_SETUP_ITEM_NUMBER = 6
    Public Const NAV_TITLE_SYS_SETUP_TEXT = "系统设置"
    Public Const NAV_TITLE_SYS_SETUP_TAG = "TitleSysSetup"
    Public Const NAV_ITEM_PRINT_SETUP_SYS_SETUP_TAG = "ItemPrintSetupSysSetup"
    Public Const NAV_ITEM_PRINT_SETUP_SYS_SETUP_TEXT = "打印设置"
    Public Const NAV_ITEM_BACKUP_RESTORE_SYS_SETUP_TAG = "ItemBackupRestoreSysSetup"
    Public Const NAV_ITEM_BACKUP_RESTORE_SYS_SETUP_TEXT = "备份/恢复数据"
    Public Const NAV_ITEM_MODIFY_PASSWORD_SYS_SETUP_TAG = "ItemModifyPasswordSysSetup"
    Public Const NAV_ITEM_MODIFY_PASSWORD_SYS_SETUP_TEXT = "修改密码"
    Public Const NAV_ITEM_CARRYOVER_SYS_SETUP_TAG = "ItemCarryOverSysSetup"
    Public Const NAV_ITEM_CARRYOVER_SYS_SETUP_TEXT = "年度结转"
    Public Const NAV_ITEM_HISTORY_DATA_SYS_SETUP_TAG = "ItemHistoryDataSysSetup"
    Public Const NAV_ITEM_HISTORY_DATA_SYS_SETUP_TEXT = "历史数据"
    Public Const NAV_ITEM_CHANGE_USER_SYS_SETUP_TAG = "ItemChangeUserSysSetup"
    Public Const NAV_ITEM_CHANGE_USER_SYS_SETUP_TEXT = "切换用户"

    Public Const NAV_GROUP_SYS_MANAGE_ITEM_NUMBER = 5
    Public Const NAV_TITLE_SYS_MANAGE_TEXT = "系统管理"
    Public Const NAV_TITLE_SYS_MANAGE_TAG = "TitleSysManage"
    Public Const NAV_ITEM_LEDGERS_SYS_MANAGE_TAG = "ItemLedgersSysManage"
    Public Const NAV_ITEM_LEDGERS_SYS_MANAGE_TEXT = "账套管理"
    Public Const NAV_ITEM_USERS_SYS_MANAGE_TAG = "ItemUsersSysManage"
    Public Const NAV_ITEM_USERS_SYS_MANAGE_TEXT = "用户管理"
    Public Const NAV_ITEM_ACCT_CONVERT_SYS_MANAGE_TAG = "ItemAcctConvertSysManage"
    Public Const NAV_ITEM_ACCT_CONVERT_SYS_MANAGE_TEXT = "科目转换工具"
    Public Const NAV_ITEM_INITIALIZE_SYS_MANAGE_TAG = "ItemInitializeSysManage"
    Public Const NAV_ITEM_INITIALIZE_SYS_MANAGE_TEXT = "初始设置"
    Public Const NAV_ITEM_CLEAR_GENERAL_LEDGER_SYS_MANAGE_TAG = "ItemClearGeneralLedgerSysManage"
    Public Const NAV_ITEM_CLEAR_GENERAL_LEDGER_SYS_MANAGE_TEXT = "清空总账"

    Public Sub Main()

        'Application.Run(frmMdiMain)
        Application.Run(sysFrmMdiMain)
    End Sub

    Public Function ConvertDbNullSingle(obj As Object) As Single
        If IsDBNull(obj) Then
            Return 0
        Else
            Return Single.Parse(obj)
        End If
    End Function

    Public Function ConvertDbNullDecimal(obj As Object) As Decimal
        If IsDBNull(obj) Then
            Return 0
        Else
            Return Decimal.Parse(obj)
        End If
    End Function

    Public Function ConvertDbNullInteger(obj As Object) As Integer

        If IsDBNull(obj) Then
            Return 0
        Else
            Return Integer.Parse(obj)
        End If

    End Function


    Public Function ConvertIntegerDbNull(ByVal i As Integer) As Object
        Return Convert.ToInt32(i)
    End Function

    ''' <summary>
    ''' 对数据库字段值进行DBNULL判断，非NULL，则转换
    ''' </summary>
    ''' <param name="obj"></param>
    ''' <returns></returns>
    Public Function ConvertDbNullString(obj As Object) As String
        If IsDBNull(obj) Then
            Return ""
        Else
            Return CType(obj, String)
        End If
    End Function

    Public Function ConvertStringDbNull(s As String) As Object
        If String.IsNullOrEmpty(s) Then
            Return ""
        Else
            Return s
        End If
    End Function

    Public Function ConvertDbNullDateTime(obj As Object) As DateTime
        If IsDBNull(obj) Then
            Return Nothing
        Else
            Return CType(obj, DateTime)
        End If
    End Function

    ''' <summary>
    ''' 返汉字拼音首字母
    ''' </summary>
    ''' <param name="s"></param>
    ''' <returns></returns>
    Public Function GetPinYinCaptial(ByVal s As String) As String
        Dim returnS As String = String.Empty

        For Each obj As Char In s
            Try
                Dim chnChar As ChineseChar = New ChineseChar(obj)
                Dim t As String = chnChar.Pinyins(0).ToString()
                returnS &= t.Substring(0, 1)

            Catch ex As Exception
                returnS &= obj.ToString()
            End Try
        Next

        Return returnS
    End Function

    ''' <summary>
    ''' 返回全拼字串
    ''' </summary>
    ''' <param name="s">汉字串</param>
    ''' <returns>拼音串</returns>
    Public Function GetPinYin(ByVal s As String) As String
        Dim returnS As String = String.Empty

        For Each obj As Char In s
            Try
                Dim chnChar As ChineseChar = New ChineseChar(obj)
                Dim t As String = chnChar.Pinyins(0).ToString()
                returnS &= t.Substring(0, t.Length - 1)

            Catch ex As Exception
                returnS &= obj.ToString()
            End Try
        Next

        Return returnS

    End Function

    Public Function CopyFile(ByVal sFileName As String, ByVal dFineName As String) As Boolean
        Try
            '判断原文件是否存在
            If (IO.File.Exists(sFileName)) Then
                IO.File.Copy(sFileName, dFineName, True)
            End If

            Return True

        Catch ex As IO.IOException
            mErrorCreater = "modGlobal - CopyFile"
            mErrorMessage = ex.Message
            mErrorNumber = -2001

            Return False
        End Try
    End Function

    Public Enum NumberConvertHzType
        ConvertHzTypeMoney = 0
        ConvertHzTypeChar = 1
    End Enum

    ''' <summary>
    '''--------------------------------------------------------------------------------
    '''将阿拉伯数字转换为大写字符串
    '''Version 1.0    2002-02-06
    '''Version 1.1    2002-04-05  修改到支持到千亿
    '''Version 1.2    2004-08-14  修改为支持 Typ,IsMoney 参数,转换结果可以不是金额,支持到百万亿
    '''Version 1.21   2004-08-15  修正 Typ=1 时,不能显示负数的疏忽.
    '''Roadbeg
    '''--------------------------------------------------------------------------------
    '''参数说明:
    '''Number         待转换的数字,可以是小数.
    '''Typ            转换类型,可选值 0,1： 0 - 转换为 零,壹,贰 等； 1 - 转换为 一,二,三 等
    '''IsMoney        是否是金额,如果是,则转换为多少元,小数后转换为多少角,分,反之则转换为类似于"二点三"这种形式
    '''--------------------------------------------------------------------------------
    '''返回值说明:
    '''如果成功,返回转换后的字符串
    '''如果失败,返回空字符串
    '''--------------------------------------------------------------------------------
    '''注意：由于 Double 类型数值范围的原因,此函数最大只支持到百万亿
    '''没有对 Typ 的值进行检查,如果 Typ 不为 0,1 之一,将会引发错误.
    '''另,由于 Double 类型数值范围的原因,超过百万亿,将不能显示小数,同样的超过十万亿只能显示一个小数,以此类推.
    ''' </summary>
    ''' <param name="conNumber"></param>
    ''' <param name="Typ"></param>
    ''' <param name="IsMoney"></param>
    ''' <returns></returns>
    Public Function ConvertNumberToHz(ByVal conNumber As Double, Optional ByVal Typ As NumberConvertHzType = NumberConvertHzType.ConvertHzTypeMoney, Optional ByVal IsMoney As Boolean = True) As String
        Dim result As String = ""                        '返回值
        Dim strNumber As String = ""                    '文本型的 Number
        Dim lngNumberLen As Long = 0                   '文本型的 Number 的 Len

        Dim strTmp As String
        Dim strFirst As String
        Dim strEnd As String = ""
        Dim lngI As Long, lngJ As Long, lngTmp As Long

        Dim strNum() As String                    '大写数字
        Dim strUnit() As String                   '单位,比如 十,拾,万等
        Dim strUnitB() As String                   '小数后的单位

        '初始化
        Select Case Typ
            Case 0
                strNum = {"零", "壹", "贰", "叁", "肆", "伍", "陆", "柒", "捌", "玖"}

                If IsMoney Then
                    strUnit = {"圆", "拾", "佰", "仟", "万", "拾", "佰", "仟", "亿", "拾", "佰", "仟", "万", "拾", "佰", "仟"}
                    strUnitB = {"角", "分"}
                Else
                    strUnit = {"点", "拾", "佰", "仟", "万", "拾", "佰", "仟", "亿", "拾", "佰", "仟", "万", "拾", "佰", "仟"}
                End If

            Case 1
                strNum = {"零", "一", "二", "三", "四", "五", "六", "七", "八", "九"}

                If IsMoney Then
                    strUnit = {"元", "十", "百", "千", "万", "十", "百", "千", "亿", "十", "百", "千", "万", "十", "百", "千"}
                    strUnitB = {"角", "分"}
                Else
                    strUnit = {"点", "十", "百", "千", "万", "十", "百", "千", "亿", "十", "百", "千", "万", "十", "百", "千"}
                End If

            Case Else
                Throw New ArgumentOutOfRangeException("转换类型只支持0 、 1")
                Return ""
        End Select

        '如果是 0 则直接转换返回
        If conNumber = 0 Then
            If IsMoney Then
                result = strNum(0) & strUnit(0) & "整"
            Else
                result = strNum(0)
            End If

            Return result
        End If

        '处理非0值 
        If IsMoney Then
            strNumber = conNumber.ToString("#.00") '保留两位小数
        Else
            strNumber = conNumber.ToString() '简单的转换为字符串型
        End If
        lngNumberLen = strNumber.Length

        '处理负数
        If strNumber.Substring(0, 1).Equals("-") Then
            strFirst = "负"
            strNumber = strNumber.Substring(1)
            lngNumberLen -= 1
        Else
            strFirst = ""  '通常不需要 =""
        End If

        '小数点
        lngI = strNumber.LastIndexOf(".")
        If lngI <> -1 Then
            strTmp = strNumber.Substring(lngI + 1)

            If IsMoney Then
                strTmp &= "00"
                strEnd = "" '通常不需要 =""

                For lngJ = 0 To 1
                    result &= strNum(Long.Parse(strTmp.Substring(lngJ, 1)))
                    result &= strUnitB(lngJ)
                Next
            Else

                For lngJ = 1 To lngNumberLen - lngI
                    result &= strNum(Long.Parse(strTmp.Substring(lngJ, 1)))
                Next
            End If

            strNumber = strNumber.Substring(0, lngI) '去除小数部分
            lngNumberLen = strNumber.Length '新的字符串长度

        Else
            If IsMoney Then
                strEnd = "整"
            Else
                strEnd = ""
            End If
        End If

        '以下为主循环部分
        lngI = 0
        For lngJ = lngNumberLen - 1 To 0 Step -1
            lngTmp = Long.Parse(strNumber.Substring(lngJ, 1))

            If lngTmp Then
                result = strNum(lngTmp) & strUnit(lngI) & result
            Else
                '超过 16 位不支持
                If lngI = 0 Or lngI = 4 Or lngI = 8 Or lngI = 12 Then
                    result = strNum(lngTmp) & strUnit(lngI) & result
                Else
                    result = strNum(lngTmp) & result
                End If
            End If

            lngI = lngI + 1
        Next

        result = result.Replace(strNum(0) & strNum(0), strNum(0)) '零零", "零
        result = result.Replace(strNum(0) & strNum(0), strNum(0)) '零零", "零

        result = result.Replace(strUnit(8) & strNum(0) & strUnit(4) & strNum(0) & strUnit(0), strUnit(8) & strUnit(0)) '亿零万零圆", "亿圆"
        result = result.Replace(strUnit(8) & strNum(0) & strUnit(4), strUnit(8) & strNum(0))       '亿零万, "亿零"
        result = result.Replace(strUnit(4) & strNum(0) & strUnit(0), strUnit(4) & strUnit(0))      '亿零万", "亿零

        result = result.Replace(strNum(0) & strUnit(8), strUnit(8))            '零亿
        result = result.Replace(strNum(0) & strUnit(4), strUnit(4))            '零万
        result = result.Replace(strNum(0) & strUnit(0), strUnit(0))            '零圆

        result = result.Replace("零角", "")
        result = result.Replace("零分", "")

        result = result.Replace(strNum(0) & strNum(0), strNum(0))              '零零", "零
        result = result.Replace(strNum(0) & strNum(0), strNum(0))              '零零", "零

        If IsMoney Then
            result = strFirst & result & strEnd
        Else
            result = strFirst & result
            '去除最后一个 "点"
            If result.Substring(result.Length - 1, 1).Equals(strUnit(0)) Then
                result = result.Substring(0, result.Length - 1)
            End If
        End If

        Return result

    End Function
End Module
